如何删除数组中的对象?

时间:2017-02-24 11:29:35

标签: javascript web

我在删除数组中的Object时遇到问题。 我认为解决方案非常简单,但我在javascript方面并不擅长。

This is my array

我想要删除此数组中的,但我有一个问题,因为它在js中有类似的东西:

myArray = [Object1,Object2,...]

并在对象中

Object1 = {SUM: "-0.75" , mont: "1", name: "test", **value: "{"25":"test"}**, year: "2017"}

感谢您的帮助。

4 个答案:

答案 0 :(得分:2)

您可以使用数组的右元素以及对象的属性property accessordelete运算符。

delete myArray[0].value;
//^^^^                   delete operator
//     ^^^^^^^           array
//            ^^^        index of array
//                ^^^^^  property

答案 1 :(得分:0)

var Arr = [{value:" xyz",name:" ajhs"},{value:" xyz",name:" jask& #34;}]

删除(ARR [1]。价值)

这将删除索引1处对象的值

答案 2 :(得分:0)

You can use several methods to remove an item from it:
//1
someArray.shift(); // first element removed
//2
someArray = someArray.slice(1); // first element removed
//3
someArray.slice(0,1); // first element removed
//4
 someArray.pop(); // last element removed

if you want to remove element at position x, use:
someArray.slice(x,1);

答案 3 :(得分:-1)

myArray = [Object1,Object2,...]
If you want to remove element at position ,     
myArray .splice(indexPosition,1);