服务端返回 输出

假设服务端返回

const data = [

   {id:1,name:”男装”,hot:true},

   {id:2,name:”女装”,hot:false},

{id:3,name:”鞋包”,hot:true},

{id:4,name:”饮料”,hot:false}

]

使用map(),在控制台中输出

{id:1,name:”男装”,hot:true},

   {id:2,name:”女装”,hot:false},

{id:3,name:”鞋包”,hot:true},

{id:4,name:”饮料”,hot:false}

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>3.打印输出</title>
	</head>

	<body>
		<script type="text/javascript">
			const data = [{
				id: 1,
				name: '男装',
				hot: true
			}, 
			{
				id: 2,
				name: '女装',
				hot: false
			},
			{
				id: 3,
				name: '鞋包',
				hot: true
			}, 
			{
				id: 4,
				name: '饮料',
				hot: false
			}]
			const newData = data.map((item, index) => {
				var newJSON = {
					id: item.id,
					name: item.name,
					hot: item.hot ? "最新" : "不新"
				}
				return newJSON
			})
			console.log(newData)
		</script>
	</body>

</html>

打印输出结果:

猜你喜欢

转载自blog.csdn.net/this_name_true/article/details/86100659