javascript-objects

javascript find by value deep in a nested object/array

谁说胖子不能爱 提交于 2019-12-19 03:19:07
问题 hello , I have a problem returning an object in my function, Let's say I have an object: var elements = [{ "fields": null, "id_base": "nv_container", "icon": "layout", "name": "container", "is_container": true, "elements" : [ //another elements set here ] }, { "id_base": "novo_example_elementsec", "name": "hello", "icon": "edit", "view": {} }]; what i want is a function (in pure javascript) that can find an object with a specific key and value , and i have created a function but its just not

Exporting all images in a Google Earth Engine image collection (Google Earth Engine API)

旧巷老猫 提交于 2019-12-18 17:28:35
问题 I need to download a bunch of Landsat images for my thesis. My problem seems simple but I don't have a clue about JavaScript and the documentation didn't help enough. I have filtered the collection to my region and time period and i want to export all images to Drive, seperately. Collection example: var surfaceReflectanceL5 = ee.ImageCollection('LANDSAT/LT5_SR'); var dateSR5=surfaceReflectanceL5.filterDate('1984-01-01', '1985-01-01'); var prSR5=dateSR5.filter(ee.Filter.eq('wrs_path', 182))

Javascript reflection: Get nested objects path

大憨熊 提交于 2019-12-18 17:14:51
问题 In this stackoverflow thread, i learnt you can get a object path via a simple string. Accessing nested JavaScript objects with string key consider the following: var person = { name: "somename", personal: { weight: "150", color: "dark" }}; var personWeight = deep_value(person,"personal.weight"); I an trying to construct an array of the object values who are not of type 'object' from my 'person' object. Hence the array would look like: [['name', []],['personal.weight', []],['personal.color', [

Creating New Objects in JavaScript

青春壹個敷衍的年華 提交于 2019-12-18 16:47:33
问题 I'm a relatively newbie to object oriented programming in JavaScript, and I'm unsure of the "best" way to define and use objects in JavaScript. I've seen the "canonical" way to define objects and instantiate a new instance, as shown below. function myObjectType(property1, propterty2) { this.property1 = property1, this.property2 = property2 } // now create a new instance var myNewvariable = new myObjectType('value for property1', 'value for property2'); But I've seen other ways to create new

How to merge objects?

匆匆过客 提交于 2019-12-18 12:05:46
问题 For instance, from these two objects : var object1 = { "color": "yellow", "size": null, "age": 7, "weight": null } var object2 = { "color": "blue", "size": 51, "age": null } I want this ( object2 overrides object1 except for null properties or properties he doesn't have): { "color": "blue", "size": 51, "age": 7, "weight": null } 回答1: Copy var src = { name: 'Apple', price: 5}; var dst= angular.copy(src); deep copy Extend : var mergedObject = angular.extend(dst, src1, src2, ...) shallow copy

JavaScript filter array of objects based on property values

ぐ巨炮叔叔 提交于 2019-12-18 08:58:33
问题 I have an array of objects in javascript. The contents look like this; obj_array = [{ "DATA_ID": 1, "DATA_NAME": "Dim", "DATA_BB_TYP": 2, "DATA_MAC": "5474", }, { "DATA_ID": 3, "DATA_NAME": "Spre", "DATA_BB_TYP": 33, "DATA_MAC": "8e30", }, { "DATA_ID": 2, "DATA_NAME": "Dimb", "DATA_BB_TYP": 2, "DATA_MAC": "45e8", }, { "DATA_ID": 4, "DATA_NAME": "Kht1", "DATA_BB_TYP": 35, "DATA_MAC": "58d0", }, { "DATA_ID": 6, "DATA_NAME": "Sens", "DATA_BB_TYP": 34, "DATA_MAC": "d004", } ] I want to retain

Aggregating object values of JavaScript arrays?

泄露秘密 提交于 2019-12-18 08:53:19
问题 In JavaScript, given n number of arrays as input in this format: (n=2) array1: [{x: 1, y: 5},{x: 2, y: 3},{x: 3, y: 6}] array2: [{x: 1, y: 2},{x: 2, y: 6},{x: 3, y: 2}] How do I aggregate the Y-values easily and get this resulting array: arrayOutput: [{x: 1, y: 7},{x: 2, y: 9},{x: 3, y: 8}] Thank you. 回答1: Update : The additional comment about the x values and their positions in the arrays makes the below irrelevant. There's no particular trick, you just loop through the arrays and build up

Get all the objects (DOM or otherwise) using JavaScript

强颜欢笑 提交于 2019-12-18 06:10:11
问题 The short version: How can I get a list of all the objects (including their descendant objects) on the page (not just the first-depth objects)? Anticipated subproblem : How can I track the visited objects as I walk the objects? Thanks in advance. The long version (with background!!): Using the in keyword we can get all the properties of an object. (And using the hasOwnProperty method allows us to filter out only the properties that belong to that object and not the inherited ones.) for (var

Get all the objects (DOM or otherwise) using JavaScript

佐手、 提交于 2019-12-18 06:09:19
问题 The short version: How can I get a list of all the objects (including their descendant objects) on the page (not just the first-depth objects)? Anticipated subproblem : How can I track the visited objects as I walk the objects? Thanks in advance. The long version (with background!!): Using the in keyword we can get all the properties of an object. (And using the hasOwnProperty method allows us to filter out only the properties that belong to that object and not the inherited ones.) for (var

JS associative object with duplicate names

僤鯓⒐⒋嵵緔 提交于 2019-12-17 20:34:34
问题 ok, so I have an object like: var myobject = { "field_1": "lorem ipsum", "field_2": 1, "field_2": 2, "field_2": 6 }; as you see there are duplicate names in the object, but with different values. If i go through it like (using jQuery): $.each(myobject, function(key, value) { console.log(key); console.log(myobject[key]); console.log(myobject[value]); } key - returns the correct key myobject[key] - returns the name for that key myobject[value] - returns the last elements', with that name, value