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

Pushing multiple list values

Now let's try pushing multiple values to a list:

const myList = List.of(1, 2, 3);
const myChangedList = myList
.push(4)
.push(5, 6)
.push(7, 8)
.push(9);

console.log('myList', myList.toJS());
// -> myList [ 1, 2, 3 ]
console.log('myChangedList', myChangedList);
// -> myChangedList List [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]

Here, the first three calls to push() create intermediary lists—you don't actually use them for anything other than as steps for building a new list. The final call to push() produces the value that ends up in myChangedList. You can see that push() accepts multiple values to add to the list. Of course, it would be better to make one call instead of four where possible. However, this isn't always possible depending on how your code is organized. I'm also using this as an opportunity to illustrate a concept.

主站蜘蛛池模板: 灌南县| 达日县| 保靖县| 偏关县| 苗栗市| 高陵县| 靖安县| 漾濞| 社旗县| 库车县| 慈溪市| 通化县| 突泉县| 辰溪县| 横山县| 景宁| 延安市| 会泽县| 南雄市| 新田县| 肇东市| 高阳县| 磴口县| 呼图壁县| 阿城市| 林芝县| 定兴县| 弋阳县| 明溪县| 兴和县| 鲁山县| 密山市| 成都市| 女性| 台中县| 内乡县| 当涂县| 万载县| 鹤壁市| 枝江市| 襄汾县|