I was trying to slice an object using Array.prototype, but it returns an empty array, is there any method to slice objects besides passing arguments or is just my code that
You can reduce the result of Object.keys function
reduce
Object.keys
const myObject = { 0: 'zero', 1: 'one', 2: 'two', 3: 'three', 4: 'four' }; const sliced = Object.keys(myObject).slice(0, 2).reduce((result, key) => { result[key] = myObject[key]; return result; }, {}); console.log(sliced);