当前位置:网站首页>JS learning notes 06-08: traversal of arrays and four methods of arrays
JS learning notes 06-08: traversal of arrays and four methods of arrays
2022-07-19 08:30:00 【The man fished alone in the cold river snow】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
// var arr=[" The Monkey King "," Pig eight quit "," The sand monk "," Tang's monk "];
// for (var i=0;i<arr.length;i++){
// console.log(arr[i]);
// }
function Person(name,age){
console.log(" name :"+this.name,+this.age)
}
var per=new Person(" The Monkey King ",18);
var per2=new Person(" Red boy ",16);
var per3=new Person(" Erlang God ",38);
var per4=new Person(" Jade Emperor ",18);
var per5=new Person(" Buddha of Tathagata ",28);
// Will these person Object into an array
var perArr=[per,per2,per3,per4,per5];
function getAdult(arr){
// Create a new array
var newArr=[];
// Traverse arr, obtain arr Medium Person object
for (var i=0;i<perArr.length;i++){
console.log(perArr[i]);
}
// Judge Person Object's age Greater than or equal to 18 if (perArr[i]>=18){
newArr.push(perArr[i]);
console.log(newArr);
}else{
console.log[perArr[i]];
}
// If greater than or equal to 18, Add this object to newArr in
// Return the new array to
return newArr;
}
var result=getAdult(perArr);
console.log(result)
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
// Create an array
var arr=[" The Monkey King "," Pig eight quit "," The sand monk "];
/* push() - This method can add one or more elements to the end of the array , And returns the new length of the array - You can pass the element to be added as an argument to the method , In this way, the element will be automatically added to the end of the array */
var result=arr.push(" Tang's monk "," Sun shangxiang "," Bones jing ");
console.log(arr);
console.log("result = "+result);// Return length , The return value is in arr in
//pop() - This method can delete the last element of the array And return the deleted element as the return value
arr.pop();
/*unshift() - Add one or more elements to the beginning of the array , And returns the new array length */
arr.unshift(" But the king bull "," Princess Iron Fan ");
console.log(arr);
//shift() - You can delete the first element of the array , And return the deleted element as the return value
</script>
</head>
<body>
</body>
</html>
边栏推荐
- Ribbon load balancing service call
- STM32CUBEIDE(9)----USART通过DMA收发
- Use of OpenCV polar transformation function warppolar
- Wvppro-zlm-gb21818-camera
- 超干货!彻底搞懂Golang内存管理和垃圾回收
- #yyds干货盘点#Cross-origin 跨域请求
- Redis 概述安装
- Stm32subeide (9) -- USART sends and receives via DMA
- 5.1 security vulnerabilities and Prevention
- 1、flask基础
猜你喜欢

Redis cache avalanche, penetration, breakdown

Eureka基础知识

Redis介绍

Viewing the technology stack of distributed system from the crash report of station B

Redis introduction

Gateway new generation gateway

Strategic model of behavioral model

Redis的发布和订阅

OpenCV极坐标转换函数warpPolar的使用

The core problem of concurrent programming
随机推荐
xgen 毛发guide历史被清理解决方法
手把手实践一个DAPP,通往Web3.0之路!
Super dry! Thoroughly understand golang memory management and garbage collection
Redis distributed lock
RestTemplate
Textview text up and down
Ribbon load balancing service call
一款关于日常习惯打卡的小程序
网传USDT和USDC要做空?带你一探究竟 | Tokenview
Sword finger offer 42 Maximum sum dynamic programming method for continuous subarrays
关于快慢指针的理解
JS学习笔记06-08:数组的遍历以及数组的四个方法
超干货!彻底搞懂Golang内存管理和垃圾回收
JS学习笔记09-12:原型对象以及Foreach+tostring及回收站
Li Kou 1669 merges two linked list notes
The latest generation of Internet: Web 3.0
No module named 'yaml' solution
力扣455分发饼干笔记
60、wsgiref手写web框架+jinja2模块初识
Redis common data types - redis list and redis set