console.log(obj[key]) // An output will be 'three' and 'seven'
}
我需要以最快的方式执行此操作,因为 obj 非常大
慕田峪4524236
浏览 232回答 3
3回答
largeQ
只需通过简单的方法即可。let obj = { 1: 'one', 2: 'two', 3: 'three', 7: 'seven'};// make sure that your case is in order// get keys of your objectconst keys = Object.keys(obj);// find index of starting keyconst index = keys.indexOf('3');// make sure index >= 0// each all keys from starting key to the end by old school wayfor (let i = index; i < keys.length; i++) { var key = keys[i]; console.log(obj[key]);}