How to get the value of an object in js (getting the value without knowing the object parameters)

1. Get the object through.

let stu = {
    
    name:"张三",age:18}
// 获取name值
let name = stu.name;

2. Obtain through []

let stu = {
    
    name:"张三",age:18}
// 获取name值
let name = stu["name"];

3. Not sure about the specific parameters to get the value

let stu = {
    
    name:"张三",age:18}
for(let i in stu){
    
    
	// 获取参数
	let param = i;
	// 获取值
	let paramValue = stu[i];
}

Acho que você gosta

Origin blog.csdn.net/dxjren/article/details/127804798
Recomendado
Clasificación