javascript - How to iterate multiarray on jquery? -
i have jquery array
i trying iterate it, first value [false, false] , cycle ends
i using function iterate
function compareandshoworhide(url) { var elem = jquery(".vanessa_content .block-title"); $.each(url_array , function( index, obj ) { $.each(obj, function( key, value ) { console.log(key); console.log(value); }); }); }
with no success, appreciated thanks
jsfiddle -> https://jsfiddle.net/xvcg0spz/
you declare url_array array,
var url_array = [];
but not using one. arrays take numerical indexes, javascript not have associative arrays (arrays take strings index).
so doing following:
url_array['/'] = [false, false]; url_array['/cart'] = [true, false]; url_array['/checkout/34'] = [true, false];
you setting properties on array object, , not adding array. array empty. since instance of array, jquery treat such , try access array elements , not properties have set.
simply declare url_array object instead , jquery iterate on properties correctly
var url_array = {}; //you should rename since not array
demo
var url_array = {}; url_array['/'] = [false, false]; url_array['/cart'] = [true, false]; url_array['/checkout/34'] = [true, false]; url_array['/user/register'] = [true, true]; url_array['/checkout/34/checkout'] = [true, false]; url_array['/checkout/34/review'] = [true, false]; url_array['/product-categories/aaaa11'] = [false, false]; url_array['/product/54/38'] = [false,false]; url_array['/our-stores'] = [true,false]; url_array['/user'] = [true,true]; url_array['/news'] = [false,false]; url_array['/shows'] = [false,false]; url_array['/content/biography'] = [false,false]; function compareandshoworhide(url) { $.each(url_array , function( index, obj ) { $.each(obj, function( key, value ) { console.log(key); console.log(value); }); }); } compareandshoworhide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
Comments
Post a Comment