Reputation: 23
I have a problem for delete an Object in an array. I think the solution is very simple but I am not good in javascript.
I want to delete the value in this array but I have a problem because of its something like that in js:
myArray = [Object1,Object2,...]
and in the object
Object1 = {SUM: "-0.75" , mont: "1", name: "test", **value: "{"25":"test"}**, year: "2017"}
Thanks for your help.
Upvotes: 0
Views: 94
Reputation: 6857
var Arr = [{value:"xyz",name:"ajhs"},{value:"xyz",name:"jask"}]
delete(Arr[1].value)
this will delete value from object at index 1
Upvotes: 0
Reputation: 252
myArray = [Object1,Object2,...]
If you want to remove element at position ,
myArray .splice(indexPosition,1);
Upvotes: -1
Reputation: 386868
You could use the right element of the array and and the property of the object with a property accessor and the delete
operator.
delete myArray[0].value;
//^^^^ delete operator
// ^^^^^^^ array
// ^^^ index of array
// ^^^^^ property
Upvotes: 2
Reputation: 4434
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);
Upvotes: 0