javascript-objects

Filter object for a nested array (Javascript)

旧时模样 提交于 2020-07-23 06:24:25
问题 Based on an object like this: var p = [ {x: [ {x1: "John"}, ] }, {x: [ {x1: "Louis"}, ] } ]; I need to filter p objects when x1 is different from any of those values: var p = [ {x: [ {x1: "Louis"}, ] }, ]; Thanks all of you for your help. 回答1: It is exactly the same as your question with the numbers. var p = [ {x: [ {x1: 'John'}, ] }, {x: [ {x1: 'Louis'}, ] } ]; const results = p.filter(val => !val.x.some(v => v.x1 === 'John')); console.log(results); 回答2: Use filter method and destructuring.

Filter object for a nested array (Javascript)

旧城冷巷雨未停 提交于 2020-07-23 06:23:34
问题 Based on an object like this: var p = [ {x: [ {x1: "John"}, ] }, {x: [ {x1: "Louis"}, ] } ]; I need to filter p objects when x1 is different from any of those values: var p = [ {x: [ {x1: "Louis"}, ] }, ]; Thanks all of you for your help. 回答1: It is exactly the same as your question with the numbers. var p = [ {x: [ {x1: 'John'}, ] }, {x: [ {x1: 'Louis'}, ] } ]; const results = p.filter(val => !val.x.some(v => v.x1 === 'John')); console.log(results); 回答2: Use filter method and destructuring.

Filter object for a nested array (Javascript)

帅比萌擦擦* 提交于 2020-07-23 06:22:33
问题 Based on an object like this: var p = [ {x: [ {x1: "John"}, ] }, {x: [ {x1: "Louis"}, ] } ]; I need to filter p objects when x1 is different from any of those values: var p = [ {x: [ {x1: "Louis"}, ] }, ]; Thanks all of you for your help. 回答1: It is exactly the same as your question with the numbers. var p = [ {x: [ {x1: 'John'}, ] }, {x: [ {x1: 'Louis'}, ] } ]; const results = p.filter(val => !val.x.some(v => v.x1 === 'John')); console.log(results); 回答2: Use filter method and destructuring.

Create nested object from query string in Javascript

こ雲淡風輕ζ 提交于 2020-07-09 13:10:42
问题 I have the following query string: student.name.firstname=Foo&student.name.lastname=Bar&student.address=My%20Street How to convert to nested object like this: { student:{ name:{ firstname: "Foo", lastname: "Bar" }, address: "My Street" } } I have tried the following code but something is wrong: function convertQueryToMap(query) { var params = {}; var vars = query.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); var subpairs; if (pair[0].includes('.')) {

Create nested object from query string in Javascript

会有一股神秘感。 提交于 2020-07-09 13:09:29
问题 I have the following query string: student.name.firstname=Foo&student.name.lastname=Bar&student.address=My%20Street How to convert to nested object like this: { student:{ name:{ firstname: "Foo", lastname: "Bar" }, address: "My Street" } } I have tried the following code but something is wrong: function convertQueryToMap(query) { var params = {}; var vars = query.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); var subpairs; if (pair[0].includes('.')) {

Create nested object from query string in Javascript

落花浮王杯 提交于 2020-07-09 13:08:51
问题 I have the following query string: student.name.firstname=Foo&student.name.lastname=Bar&student.address=My%20Street How to convert to nested object like this: { student:{ name:{ firstname: "Foo", lastname: "Bar" }, address: "My Street" } } I have tried the following code but something is wrong: function convertQueryToMap(query) { var params = {}; var vars = query.split('&'); for (var i = 0; i < vars.length; i++) { var pair = vars[i].split('='); var subpairs; if (pair[0].includes('.')) {

javascript for loop changes original list variable

偶尔善良 提交于 2020-07-03 10:28:26
问题 I have a collection of objects called the response and I am creating another variable called object that's an empty object and creating object.array and set it to the response variable. I would think I am creating a new scope. However, if I set the age inside object.array as null, this sets the age in my response array to null . Why is this happening and how can I create a duplicate variable that doesn't affect the original? I need to keep the above variables as is. So object needs to be an