[英]Get items for selected item from array
I have array like this structure我有这样的结构数组
["12 18:00", "15 17:30","16 12:00", "12 21:30", "9 10:30"...]
and it has unknown number of elements.它有未知数量的元素。 I want get every hour:minute for selected element.
我想每小时获取选定元素的分钟数。 Example: if ele=="12" then get 18:00, 21:30.
示例:如果 ele=="12" 那么得到 18:00, 21:30。 Maybe array has more "12 16:30","12 13:00" etc elements.
也许数组有更多的 "12 16:30","12 13:00" 等元素。 Then also get 16:30, 13:00.
然后也得到16:30、13:00。 All get elements 18:00, 21:30, 16:30, 13:00
所有获取元素 18:00, 21:30, 16:30, 13:00
Help me for this solution.帮我解决这个问题。
You can do this:你可以这样做:
const array = ["12 18:00", "15 17:30","16 12:00", "12 21:30", "9 10:30"];
const getItems = number => {
return array.filter(item => item.split(" ")[0] === number.toString()).map(item => item.split(" ")[1])
}
console.log(getItems(12));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.