标签云

微信群

扫码加入我们

WeChat QR Code

This question already has an answer here:

I have an array that I am using, I am having difficulties describing what kind of an array it is, which is making it hard for me to work with it. So far it works for me. I am just curious.

I eventually want to remove the end of this array.

I tried .pop() and .grep(). Its not working.

Here is an example of my code.

var options = {};
$('.option:visible').each(function(){
     var option_label = "";
     var option_selected = [];
     var option_img = "";

     ...


     options[option_label] = {
         option_selected: option_selected,
         option_image : option_img
     };
});

What I am trying to do is:

if(option_label.indexOf("something") != -1) {
   //then pop off options
} 
//continue about your business

For clarification I wont know the exact title of the option_label.


options is an object. In JS, you can add properties to objects using obj[propName].

2018年07月23日10分15秒

Which variable are you referring to? option_selected? That's the only array I see.

2018年07月23日10分15秒

The only array that you have is option_selected = [], and that is already empty, so what are you trying to remove from it?

2018年07月23日10分15秒

"options" isn't an array. It's an object, which contains key-value pairs. You can't pop()object properties because they're not guaranteed to be in any set order. Therefore there is no "end" or "last" you can get rid of ...Looks like others beat me to linking the related question.

2018年07月23日10分15秒

He obviously didn't realise it was an object (hence the question "what is this array called"). therefore the "possible duplicate of" doesn't really make sense...

2018年07月23日10分15秒