官术网_书友最值得收藏!

Pushing values to lists

You can push a new value onto a list using the push() method, as follows:

const myList = List.of(1, 2, 3);
const myChangedList = myList.push(4);

console.log('myList', myList.toJS());
// -> myList [ 1, 2, 3 ]
console.log('myChangedList', myChangedList.toJS());
// -> myChangedList [ 1, 2, 3, 4 ]

The end result of calling push(4) is a new list. If you want to make use of this list, you have to store it somewhere. In this example, we just want to print the JSON representation of the list, and as you can see, 4 is added to myChangedList. You can also see that the contents of myList haven't changed. Of course not—it's immutable!

主站蜘蛛池模板: 察雅县| 包头市| 商洛市| 新津县| 图片| 准格尔旗| 五峰| 无极县| 祁阳县| 永吉县| 祁阳县| 竹溪县| 金门县| 新丰县| 潮安县| 青铜峡市| 宣威市| 恩施市| 泰兴市| 睢宁县| 南京市| 宁海县| 麻栗坡县| 晋中市| 澜沧| 南丹县| 孟津县| 临邑县| 卓资县| 芦溪县| 田林县| 纳雍县| 阿城市| 长沙县| 商丘市| 莱西市| 汨罗市| 陆川县| 油尖旺区| 中西区| 永登县|