当前位置:网站首页>js创建数组(元素都是对象)
js创建数组(元素都是对象)
2022-06-23 05:07:00 【灯笼只能来教室体验生活】
js创建数组(数组元素都是对象)
对象
var obj = {
//属性1
attribute1:' ',
//属性2
attribute2:' '
}
数组
这里创建的是空数组,并且不会指定数组元素的类型
//方法1
var arr = [];
//方法2
var arr = new Array();
给数组添加元素
var test = function(){
//数组
var arr = [];
for(let i=0;i<5;i++){
//临时对象
let obj = {
//属性1
x: Math.random()*10 ,
//属性2
y: Math.random()*10
};
arr.push(obj);
}
//打印属性
for(let i=0;i<arr.length;i++){
console.log("x: "+arr[i].x);
console.log("y: "+arr[i].y);
}
}
push方法介绍

控制台输出结果

边栏推荐
- 【接口自动化】软件测试涨薪核心技能、让薪资涨幅200%
- 【DaVinci Developer专题】-42-如何生成APP SWC的Template和Header文件
- SQL statement error caused by the same SQL table name and function name.
- Day_ 05 smart communication health project - appointment management - appointment settings
- bootstrap如何清除浮动的样式
- [cocos2d-x] custom ring menu
- A review: neural oscillation and brain stimulation in Alzheimer's disease
- Leetcode topic resolution valid anagram
- mysql读已提交和可重复度区别
- Eight data analysis models: ogsm model
猜你喜欢

Day_07 传智健康项目-Freemarker

业务逻辑安全思路总结

Learning Tai Chi Maker - esp8226 (11) distribution network with WiFi manager Library

又到半年总结时,IT人只想躺平

Progress of layer 2 technical scheme

Day_ 01 smart communication health project - project overview and environmental construction

Day_ 11 smart communication health project - graphic report and poi Report

Day_10 传智健康项目-权限控制、图形报表

Efficient office of fintech (I): automatic generation of trust plan specification

【接口自动化】软件测试涨薪核心技能、让薪资涨幅200%
随机推荐
给定二叉树的某个节点,返回该节点的后继节点
开源生态|超实用开源License基础知识扫盲帖(下)
sklearn sklearn中classification_report&精确度/召回率/F1值
In the half year summary, it people just want to lie flat
CPU的功能和基本结构
Shutter style
sklearn sklearn中的模型调参利器 gridSearchCV(网格搜索)
The softing datafeed OPC suite stores Siemens PLC data in an Oracle Database
射频内容学习
[DaVinci developer topic] -41-app how SWC reads and writes NVM block data
Illuminate\Support\Collection 去重 unique 列表去重
JVM原理简介
(1) Basic learning - Common shortcut commands of vim editor
Introduction to JVM principle
去除防火墙和虚拟机对live555启动IP地址的影响
100-300 cases of single chip microcomputer program (detailed explanation of notes)
程序员的真实想法 | 每日趣闻
百度URL参数之LINK?URL参数加密解密研究(代码实例)
Jour 13 Projet de santé mentale - chapitre 13
Leetcode topic resolution single number