Except for in the cycle, with an array of objects at

 
// Array
was arr = [1,2,9];
        function join(array,sign){
            var str = "";
            for(var item in array){
                console.log(typeof item);//string
                console.log(typeof array.length);//number
                console.log (item); // 0 1 2 item type String
                if(item==array.length-1){
                    sign = "";
                }
                str += array[item] + sign;
            }
            return str;
        }
        console.log(join(arr,"#"));
        join(arr);



// Objects

        var obj = {
        a:1,
        b:2,
        c:3,
        d:{
            a:1,b:2
        }
    }

 

    for(var prop in obj){
        // prop key is that all property names under obj
        // each cycle will be paid to prop variable attribute names
        console.log(prop,obj[prop]);
    }

Guess you like

Origin www.cnblogs.com/miniSkytrue/p/12121919.html