简体   繁体   English

如何从ImmutableJS中的对象内部的数组中删除元素

[英]How to delete an element from an array which is inside an object in ImmutableJS

if i have an object like so: 如果我有这样的对象:

var fruitList = Immutable.map ({ fruits: [apples, oranges, mangoes]});

How do i delete one of the element of the array while maintaining immutability. 我如何在保持不变性的同时删除数组的元素之一。

var newList = {fruits: [apples, oranges]};

您可以尝试以下方法:

var newList = fruitList.get('fruits').delete(fruitList.get('fruits').findIndex(fruit => fruit === 'mangoes'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM