当前位置:网站首页>JS to create an array (all elements are objects)
JS to create an array (all elements are objects)
2022-06-23 06:41:00 【Lanterns can only come to the classroom to experience life】
js Create array ( Array elements are objects )
object
var obj = {
// attribute 1
attribute1:' ',
// attribute 2
attribute2:' '
}
Array
What is created here is an empty array , And does not specify the type of the array element
// Method 1
var arr = [];
// Method 2
var arr = new Array();
Add elements to the array
var test = function(){
// Array
var arr = [];
for(let i=0;i<5;i++){
// Temporary objects
let obj = {
// attribute 1
x: Math.random()*10 ,
// attribute 2
y: Math.random()*10
};
arr.push(obj);
}
// Print properties
for(let i=0;i<arr.length;i++){
console.log("x: "+arr[i].x);
console.log("y: "+arr[i].y);
}
}
push Methods to introduce

Console output

边栏推荐
- Leetcode topic resolution remove nth node from end of list
- 综合培养学生脑力思维的少儿编程
- 解读创客教育中的团结协作精神
- 解析创客教育中的个性化学习进度
- leetcode - 572. 另一棵树的子树
- Plot+seaborn+folium: a visual exploration of Abbey's rental housing data
- Topic35——34. 在排序数组中查找元素的第一个和最后一个位置
- Day_ 09 smart health project - mobile terminal development - Mobile quick login and permission control
- mysql如何将日期转为数字
- 杂七杂八的东东
猜你喜欢

Detailed explanation of redis persistence, master-slave and sentry architecture

C# wpf 附加属性实现界面上定义装饰器

sklearn sklearn中的模型调参利器 gridSearchCV(网格搜索)

Index - MySQL

杂七杂八的东东

从 WAN 到 SD-WAN 边缘设备的网络架构

快速认识 WebAssembly

中台库存中的实仓与虚仓的业务逻辑设计

Gridsearchcv (grid search), a model parameter adjuster in sklearn

Day_ 04 smart health project - appointment management - package management
随机推荐
图解 Google V8 # 17:消息队列:V8是怎么实现回调函数的?
QT creator builds osgearth environment (osgqt msvc2017)
Summary of business logic security ideas
In the half year summary, it people just want to lie flat
Easy EDA #学习笔记09# | ESP32-WROOM-32E模组ESP32-DevKitC-V4开发板 一键下载电路
中台库存中的实仓与虚仓的业务逻辑设计
Vs+qt project transferred to QT Creator
sklearn sklearn中的模型调参利器 gridSearchCV(网格搜索)
Functions and basic structure of CPU
直播带货这么火,如何在小程序中实现视频通话及直播互动功能?
Day_05 传智健康项目-预约管理-预约设置
Day_06 传智健康项目-移动端开发-体检预约
C语言 获取秒、毫秒、微妙、纳秒时间戳
ffplay实现自定义输入流播放
mysql如何将日期转为数字
Haas506 2.0 development tutorial - Advanced Component Library -modem Sim (only supports versions above 2.2)
Day_04 传智健康项目-预约管理-套餐管理
Day_ 07 smart communication health project FreeMarker
Day_01 传智健康项目-项目概述和环境搭建
CPU的功能和基本结构