-2

Possible Duplicate:
JavaScript Array Delete Elements

How is this done?

If I have the following array defined:

var myArr = []; myArr[id1] = {prop1: prop1Value, prop2:prop2Value}; myArr[id2] = {prop1: prop1Value, prop2:prop2Value}; //etc 

I wish to delete myArr[id1]

2
  • Dear Patricia, it's not a duplicate. No answer in the question above answers my question. If you think otherwise, it would be great if you posted some code that does. Regards. Commented Nov 17, 2011 at 19:06
  • Please note that this is an associative array so it lacks splice(), hence the "duplicate" question doesn't actually answer this one. Please actually READ the question before clicking to close. Commented Nov 17, 2011 at 19:27

1 Answer 1

4

Perhaps you mean that the numerical indices after the deleted element aren't updated... in which case you'll need to use splice:

myArr.splice(id1, 1); 
Sign up to request clarification or add additional context in comments.

2 Comments

no splice() on associative arrays in JS
@sarsnake Because associative arrays are just objects, and the only way to delete a property of an object is to use delete: delete myArr[id1];. The reason myArr[id1] still returns undefined is because that's what happens when you check a property that doesn't exist: myArr.fippetyFloppityFloo also returns undefined...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.