为什么这个对象的键是字符串?

Dav*_*vid 0 javascript

鉴于:

request = .ajax({
    method: 'POST',
    data : JSON.stringify(object),
    url : 'offline_ajax_queue.php',
    contentType : 'application/json',
    dataType : 'json',
    cache : false,
    success : function(response) {
        console.log(response);
        for (var key in response) {
            if (response.hasOwnProperty(key)) {
                console.log(key, response[key]);
                if(response[key] > -1)
                    removeAction(key);
            }
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

并在控制台中,响应=

{1: 1, 2: 0, 3: 0, 4: 0}
Run Code Online (Sandbox Code Playgroud)

和:

typeof response[key]  //  "number"
Run Code Online (Sandbox Code Playgroud)

为什么钥匙string而不是number

typeof key  //  "string"
Run Code Online (Sandbox Code Playgroud)

Que*_*tin 5

对象属性名称始终是字符串或符号,从不是数字.

(Map可以包含不同数据类型的键).