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

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!

主站蜘蛛池模板: 峨眉山市| 登封市| 青龙| 隆昌县| 宜丰县| 静宁县| 旅游| 武宁县| 噶尔县| 秦安县| 兴隆县| 延寿县| 江北区| 水富县| 湟源县| 渭南市| 阿坝| 平舆县| 广南县| 内江市| 新宁县| 常山县| 青川县| 丹江口市| 临沭县| 额尔古纳市| 高邮市| 塘沽区| 顺义区| 息烽县| 遂昌县| 日喀则市| 鲁山县| 泸定县| 望江县| 曲松县| 宜章县| 遵义市| 兴和县| 黄冈市| 平定县|