简体   繁体   English

如何从数组中删除特定元素? 带字符串索引

[英]How to delete a specific element from array? with String Index

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. 因此,它是关于二维数组,我想删除program [“ first”]下的所有内容,包括删除该数组。 How to do this in pure JavaScript without JQuery? 没有JQuery的纯JavaScript如何做到这一点?

它是一个object而不是array ,因此请使用:

delete workout.program.first;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM