js 数组集合过滤取值

原始数据

(6) [{…}, {…}, {…}, {…}, {…}, {…}]
  0:
  assId: 1
  categoryList: []

> disableLeverList: (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
  id: 1
  level: []
  reasonList: (13) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
  typeCode: "1"
  typeName: "1"
  typeValue: "1"
  __proto__: Object
  1:
  assId: 2
  categoryList: []
> disableLeverList: (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
  id: 2
  level: []
  reasonList: (15) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
  typeCode: "2"
  typeName: "2"
  typeValue: "1"
  __proto__: Object
  2:
  assId: 3
  categoryList: []
> disableLeverList: (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
  id: 3
  level: []
  reasonList: (15) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
  typeCode: "3"
  typeName: "3"
  typeValue: "1"
  __proto__: Object

想得到

(6) [{…}, {…}, {…}, {…}, {…}, {…}]
  0:
  assId: 1
  categoryList: []
> disableLeverList: (4) [{…}, {…}, {…}, {…}]
  id: 1
  level: []
  reasonList: (13) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
  typeCode: "1"
  typeName: "1"
  typeValue: "1"
  __proto__: Object
  1:
  assId: 2
  categoryList: []

> disableLeverList: (4) [{…}, {…}, {…}]
  id: 2
  level: []
  reasonList: (15) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
  typeCode: "2"
  typeName: "2"
  typeValue: "1"
  __proto__: Object
  2:
  assId: 3
  categoryList: []
> disableLeverList: (4) [{…}, {…}, {…}, {…}]
  id: 3
  level: []
  reasonList: (15) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
  typeCode: "3"
  typeName: "3"
  typeValue: "1"
  __proto__: Object

我想取最大数组(length为6)下的disableLeverList数组,需要拿取disableLeverList数组的前4个值,后面的6个值过滤掉,然后不影响数组数组结构和最大数组(length为6)

阅读 2.9k
2 个回答
function transform(arr){
    return arr.map(item => {
        item.disableLeverList = item.disableLeverList.slice(0, 4);
        return item;
    })
}
arr[arr.length -1 ].disableLeverList.slice(0,4)

//楼主改过题目,答案无效

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题