In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is a detailed introduction to "javascript array can not contain objects", detailed content, clear steps, details properly handled, I hope this "javascript array can not contain objects" article can help you solve doubts, the following follow the small series of ideas slowly in-depth, together to learn new knowledge bar.
JavaScript arrays can contain objects. javascript array is a collection of data arranged in order, the array can contain any type of data, that is, the type of array elements is not limited, can be a number, string, array, Object and other types.
Operating environment of this tutorial: Windows 7 system, Javascript version 1.8.5, Dell G3 computer.
JavaScript arrays can contain objects.
An array is a collection of sequentially arranged data, each value in the array is called an element, and the array can contain any type of data.
Examples:
let arr = [1,'hello',true,[1,2],{name: 'Bob',age:20}];console.log(arr);
As you can see, when defining arrays and assigning values, the values of array elements can be numbers, strings, booleans, arrays, objects, and so on.
In short, there are no restrictions on the types of array elements.
Extended knowledge: pseudo-class arrays
Pseudo-class arrays, also known as class arrays, are objects with array-like structures. Simply put, the property name of the object is a non-negative integer, and it starts from 0, increases sequentially, and contains the length attribute. It should also ensure that its value is dynamically consistent with the number of ordered subscript attributes, so as to facilitate iterative operations on pseudo-class arrays. The jQuery object is known as a pseudo-class array.
example
In the example below, obj is an object literal that JavaScript no longer treats as an array subscript when assigned to it using an array subscript, but as an attribute name of the object.
var obj = {}; //define object literal obj[0] = 0;obj[1] = 1;obj[2] = 2;obj.length = 3;console.log(obj["2"]); //returns 2
It is equivalent to an object direct quantity.
var obj = { 0 : 0, 1 : 1, 2 : 2, length : 3};
Because numbers are illegal identifiers, you cannot read or write attributes using dot syntax.
console.log(obj.0);
Instead, you should use bracket syntax to read and write attributes.
console.log(obj["2"]); Read here, this article "javascript array can not contain objects" article has been introduced, want to master the knowledge of this article also need to practice to understand, if you want to know more about the content of the article, welcome to pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.