本文介绍了如果长度>如何修剪数组5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果长度> 5,如何修剪数组
How to trim the array if length is > 5
我的JSON是:
{
"name": "aaa"
"files": [
{
"name": "A",
"link": "string.com"
},
{
"name": "Q",
"link": "string.com"
},
{
"name": "M",
"link": "string.com"
},
{
"name": "New Filters Reports",
"link": "string.com"
},
{
"name": "U",
"link": "string.com"
}
],
"titles": [
"A",
"B",
"C",
"D",
"E",
"F"
]
}
我要检查标题"的长度是否大于5,它应该修剪5之后的值,并且应该在屏幕上仅显示5个标题.
I want to check if "titles" length is greater than 5, it should trim the values after 5 and should display only 5 titles on screen.
推荐答案
您可以为此使用slice.
You can use slice for that.
let trimmed = data.titles.slice(0, 5);
这篇关于如果长度>如何修剪数组5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!