Check if an array item is set in JS

前端 未结 9 1111
别跟我提以往
别跟我提以往 2021-02-02 08:10

I\'ve got an array

    var assoc_pagine = new Array();
    assoc_pagine[\"home\"]=0;
    assoc_pagine[\"about\"]=1;
    assoc_pagine[\"work\"]=2;
9条回答
  •  执念已碎
    2021-02-02 08:38

    This worked for me

    if (assoc_pagine[var] != undefined) {
    

    instead this

    if (assoc_pagine[var] != "undefined") {
    

提交回复
热议问题