What is undefined x 1 in JavaScript?

var trees = ["redwood","bay","cedar","oak","maple"];
delete trees[3];

When you run the code above and type console.log(trees); into your Chrome developer console, you will get
["redwood", "bay", "cedar", undefined × 1, "maple"]. When you run the code in Firefox’s browser console, you will get ["redwood", "bay", "cedar", undefined, "maple"]. Thus, it’s clear that the Chrome browser has its own way of displaying uninitialised indexes in arrays. However, when you check trees[3] === undefined in both browsers, you will get similar output as true.

Asked on January 18, 2019 in Javascript.
Add Comment


  • 5 Answer(s)

    That seems to be Chrome’s new way of displaying uninitialized indexes in arrays (and array-likeobjects):

    > Array(100)
    [undefined × 100]

    Which is certainly better than printing [undefined, undefined, undefined,...] or however it was before.

    Although, if there is only one undefined value, they could drop the x 1.

    Answered on January 19, 2019.
    Add Comment

    Part of the ECMA standard , Javascript consoles will display objects as arrays when the objects are array-like. Such as: [“hello”, “world”] for an object containing strings that are numerically indexed. JavaScript arrays are implemented differs from browser to browser, but they generally fall back to asparse implementation – most likely the same one used for property access of regular objects. However, Google Chrome seems to choose to display sparse array using this undefined x n notation. Here is how it looks, Type this code intoChrome developer console :

    output

    Above output show, the first two consecutive “undefined” that are represented by *2, to show that there are two consecutive undefined there. Although, if there is only one undefined value, they could drop the x 1. Thus, it’s clear that the Chrome browser has its own way of displaying uninitialized indexes in arrays.

    Answered on January 20, 2019.
    Add Comment

    That seems to be Chrome’s new way of displaying uninitialized indexes in arrays (and array-like objects):

    > Array(100)
    [undefined × 100]
    Which is certainly better than printing [undefined, undefined, undefined,…] or however it was before.

    Although, if there is only one undefined value, they could drop the x 1.
    Google Chrome seems to choose to display sparse array using this undefined x n notation. It will show [undefined, undefined] if it is not a sparse array:

    var arr = new Array(2);
    console.log(arr);

    var arr2 = [];
    arr2[3] = 123;
    console.log(arr2);

    var arr3 = [,,,];
    console.log(arr3)

    var arr4 = [,];
    console.log(arr4)

    var arr5 = [undefined, undefined]
    console.log(arr5)

    var arr6 = [undefined]
    console.log(arr6)
    arr1 to arr4 are all sparse arrays, while arr5 and arr6 are not. Chrome will show them as:

    [undefined × 2]
    [undefined × 3, 123]
    [undefined × 3]
    [undefined × 1]
    [undefined, undefined]
    [undefined]
    note the [undefined x 1] for the sparse array.

    Since you deleted an element, it follows that: If you delete an element from an array, the array becomes sparse.

    Answered on January 27, 2019.
    Add Comment

    Google Chrome seems to choose to display sparse array using this undefined x n notation. It will show [undefined, undefined] if it is not a sparse array:

    var arr = new Array(2);
    console.log(arr);

    var arr2 = [];
    arr2[3] = 123;
    console.log(arr2);

    var arr3 = [,,,];
    console.log(arr3)

    var arr4 = [,];
    console.log(arr4)

    var arr5 = [undefined, undefined]
    console.log(arr5)

    var arr6 = [undefined]
    console.log(arr6)
    arr1 to arr4 are all sparse arrays, while arr5 and arr6 are not. Chrome will show them as:

    [undefined × 2]
    [undefined × 3, 123]
    [undefined × 3]
    [undefined × 1]
    [undefined, undefined]
    [undefined]
    note the [undefined x 1] for the sparse array.

    Since you deleted an element, it follows that: If you delete an element from an array, the array becomes sparse.

    Answered on February 4, 2019.
    Add Comment

    That seems to be Chrome’s new way of displaying uninitialized indexes in arrays (and array-like objects):

    > Array(100)
    [undefined × 100]

    Which is certainly better than printing [undefined, undefined, undefined,...] or however it was before.

    Although, if there is only one undefined value, they could drop the x 1.

     

     

     

     

     

     

    Answered on February 5, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.