简体   繁体   English

如何删除 object 数组的 object 键值?

[英]How to remove object key value of an object array?

I have an object array with object key value.我有一个带有 object 键值的 object 数组。

arr = [obj1:{name:"Jack", surname:"Peralto"}, obj2:{name:"Husnu", surname:"White"}]

I do not want to see obj1 and obj2 labels.我不想看到obj1obj2标签。 Because of these labels I could not use a word template package.由于这些标签,我无法使用单词模板 package。

So I want to convert it to this form.所以我想把它转换成这种形式。

arr = [{name:"Jack", surname:"Peralto"}, {name:"Husnu", surname:"White"}]

.map function does not work at first array. .map function 在第一个阵列中不起作用。

arr.map(o=>o) arr.map(o=>o)

Why I have an array like this?为什么我有这样的数组? I should use reduce function and obj1 and obj2 labels are key value when I create object array.当我创建 object 数组时,我应该使用 reduce function 和obj1obj2标签是键值。 Now I don't need them.现在我不需要它们了。

When you fix the syntax errors in your code ( [obj1:{... is not a valid data structure) you can use Object.values to get at the nested objects.当您修复代码中的语法错误时( [obj1:{...不是有效的数据结构),您可以使用Object.values来获取嵌套对象。

 const arr = { obj1: { name: "Jack", surname: "Peralto" }, obj2: { name: "Husnu", surname: "White" } }; console.log(Object.values(arr));

its not the right syntax of array you have used array don't have key value pair它不是您使用的数组的正确语法数组没有键值对

use this syntax if you are using object of objects with key value pair如果您正在使用具有键值对的对象的 object,请使用此语法

const obj = {
  obj1: {
    name: "Jack",
    surname: "Peralto"
  },
  obj2: {
    name: "Husnu",
    surname: "White"
  }
};

or use this an array contains object或者使用这个包含 object 的数组

arr = [
{name:"Jack", surname:"Peralto"},
 {name:"Husnu", surname:"White"}
]

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

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