If you want RxJS-way solution, it might look something like this:
ES6 syntax:
const arr = [
{
name:"1",
args: [1,2,3,4,5]
},
{
name:"2",
args: [2,3,4,5,6]
}
]
Rx.Observable
.from(arr) // 1
.map(item => { // 2
return {
...item,
args: item.args.filter(arg => arg >= 4) // 3
}
})
.reduce((acc, value) => [...acc, value], []) // 4
.subscribe(result => {
console.log(result) // 5
})
ES5 syntax:
var arr = [
{
name:"1",
args: [1,2,3,4,5]
},
{
name:"2",
args: [2,3,4,5,6]
}
]
Rx.Observable
.from(arr)
.map(function(item) {
return {
name: item.name,
args: item.args.filter(function(arg) {
return arg >= 4
})
}
})
.reduce(function(acc, value) {
return [].concat(acc, value)
}, [])
.subscribe(function(result) {
console.log(result)
})
- Create Observable sequence from array
- Modify each streamed item in array corresponding to your needs
- Actual
args filtering
- Reduce all streamed results into one array (you can remove this line if you want then process each item of array one-by-one, not the whole array)
- Do something with result
Some useful links: