0

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.

4 Answers 4

2

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
Sign up to request clarification or add additional context in comments.

Comments

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);

1 Comment

funny, i think it is to remove a property of the object, not to remove an element of the array ...
0

var Arr = [{value:"xyz",name:"ajhs"},{value:"xyz",name:"jask"}]

delete(Arr[1].value)

this will delete value from object at index 1

Comments

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

2 Comments

thank, for your answers but is for remove property of the object in my array, not to remove an element of the array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.