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

  • Mastering Immutable.js
  • Adam Boduch
  • 116字
  • 2021-07-08 10:30:10

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!

主站蜘蛛池模板: 石阡县| 牟定县| 大方县| 祁阳县| 常宁市| 长岭县| 南岸区| 冀州市| 来宾市| 兴化市| 彩票| 新昌县| 都安| 通化市| 马尔康县| 罗山县| 怀来县| 兴和县| 张家口市| 浏阳市| 新津县| 炉霍县| 左云县| 柯坪县| 尚义县| 平乡县| 淳化县| 西贡区| 福州市| 光泽县| 虹口区| 襄樊市| 奉贤区| 同仁县| 罗平县| 周口市| 库车县| 辉县市| 扎赉特旗| 黔西县| 黑龙江省|