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

  • 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!

主站蜘蛛池模板: 邳州市| 壤塘县| 景泰县| 安康市| 秦安县| 衡山县| 蒙山县| 花莲县| 白朗县| 沂源县| 南安市| 高尔夫| 涪陵区| 额济纳旗| 都昌县| 秦安县| 宁安市| 大冶市| 磐石市| 云梦县| 定州市| 台前县| 万全县| 寿宁县| 曲水县| 满洲里市| 荆州市| 广宁县| 长寿区| 县级市| 津南区| 大丰市| 文成县| 揭阳市| 乐至县| 凯里市| 天等县| 巍山| 松桃| 博白县| 黔江区|