Traverse through Javascript object properties

前端 未结 8 1834
清酒与你
清酒与你 2021-01-31 01:48

I want to traverse through JavaScript object\'s property

    var obj =
    {
        a: \'value1\',
        b: \'value2\',
        c: \'value3\',
        d: \'va         


        
8条回答
  •  没有蜡笔的小新
    2021-01-31 02:17

    You should check that the property belongs to the object and not a prototype.

    for (var prop in obj) {
        if (obj.hasOwnProperty(prop)) {
            obj[prop] = 'xxx';
        }
    }
    

提交回复
热议问题