B.Denis
B.Denis

Reputation: 23

How can i delete an object in a array?

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.

This is my array

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

Answers (4)

Ankit Raonka
Ankit Raonka

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

Amol B Lande
Amol B Lande

Reputation: 252

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

Upvotes: -1

Nina Scholz
Nina Scholz

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

savani sandip
savani sandip

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

Related Questions