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

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.

主站蜘蛛池模板: 祥云县| 寿宁县| 丹江口市| 基隆市| 枣阳市| 民乐县| 赤水市| 财经| 肥东县| 波密县| 定结县| 峨山| 长海县| 孟连| 华阴市| 庄浪县| 晋中市| 丹棱县| 广宁县| 浠水县| 田阳县| 延津县| 沾化县| 新乡市| 平阳县| 呼和浩特市| 宝丰县| 宁武县| 潞西市| 齐齐哈尔市| 诸暨市| 乐亭县| 河源市| 城口县| 沽源县| 梁河县| 缙云县| 鲁山县| 开封市| 吴堡县| 商都县|