Why Object.keys is returns array of string instead of array of Numbers

Keys are always of a String type. If you need numbers you will have to cast them manually:

var obj = { 0: 'a', 1: 'b', 2: 'c' };
var ids = Object.keys(obj).map(Number);

console.log(ids);

Leave a Comment