- Mastering Immutable.js
- Adam Boduch
- 147字
- 2021-07-08 10:30:10
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.
推薦閱讀
- JavaScript+jQuery開發實戰
- Instant Typeahead.js
- Python程序設計
- Building Minecraft Server Modifications
- 人人都懂設計模式:從生活中領悟設計模式(Python實現)
- 碼上行動:用ChatGPT學會Python編程
- SQL基礎教程(第2版)
- INSTANT JQuery Flot Visual Data Analysis
- Software Architecture with Python
- Spring Boot學習指南:構建云原生Java和Kotlin應用程序
- 深度學習:基于Python語言和TensorFlow平臺(視頻講解版)
- R統計應用開發實戰
- Python AI游戲編程入門:基于Pygame和PyTorch
- 瘋狂Ajax講義(第3版)
- 區塊鏈原理、設計與應用