Why is there no length property in this object?

problem description

related codes

<script>
    let arrayLike = {
        "0": "a",
        "1": "b",
        "2": "c",
        length: 3
    };

    var arr2 = Array.from(arrayLike); // ["a", "b", "c"]
    console.log(arrayLike)
    console.log(arr2)
</script>




<div id="liuyu"></div>
<script>
    $(document).ready(function(){
        $.ajax({
            method: "GET",
            url: "https://randomuser.me/api/ ",
            success:function( data ) {
                var nihao= data.results[0].id;
                console.log(nihao)
                console.log(Array.from(nihao))
             }  ,error:function(){
                return false;
            }
        })
    })
</script>



Nov.19,2021

you can take a look at this answer
Why does the object have no length attribute?

if you want to get the length attribute, you can add

to the prototype.
var a = {a:1,b:2,c:3,d:4};
 Object.prototype.length = function() {
 var count = 0;
    for(var i in this){
        if(this.hasOwnProperty(i)){//
            countPP;
        };
    };
    return count;   

 };
 alert(a.length());
Menu