0

How to remove/delete a specific element from an array with as index a string instead of numbers? this is my code:

workout.program = new Array();
workout.program["first"] = new Array();
workout.program["first"]["time"] = 10;
workout.program["first"]["speed"] = "medium";
workout.program["first"]["slope"] = 0;

So it's about a 2d Array, and i want to delete everything which is under program["first"] including to delete that Array. How to do this in pure JavaScript without JQuery?

2
  • workout.program["first"] = undefined Commented Sep 17, 2013 at 15:35
  • If you're going to be accessing elements with strings, maybe consider using a dictionary? Commented Sep 17, 2013 at 15:38

1 Answer 1

1

It's an object not an array, so use:

delete workout.program.first;
Sign up to request clarification or add additional context in comments.

1 Comment

You access arrays using a numerical index, objects by keys. workout is an object. workout.program is an object, and workout.program.first is an object, despite you trying to code it as an 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.