Questions tagged [object-object-mapping]

20439 questions
1

votes
3

answer
137

Views

JSON to Python objects

I am deliberating about how to transfer the complex information from a JSON API response to (several) Python objects. I have included the (lengthy) model response below. Note that some values are not always included in the response, and some values are a list of dictionaries. Is there an 'easy' way...
Dave
-1

votes
3

answer
22

Views

Acessing nested objects dynamically [duplicate]

This question already has an answer here: How can I access and process nested objects and arrays? 21 answers I need to count the number of online user in this nested object, and return the total. I've tried this code but I am kind of lost let users = { Alan: { age: 27, online: false }, Jeff: { age:...
Redcoat
0

votes
0

answer
16

Views

Looping through array of objects to update another array of objects updates all objects

I currently have two arrays of objects that look like this: array1 [ { _id: { salesmanId: '5c50b6971c9d440000a4a865', week: 0 }, salesmanId: '5c50b6971c9d440000a4a865', week: 0, created: '2019-01-01T21:31:51.993Z', name: 'Craig Howell', value: 0.5 }, { _id: { salesmanId: '5c50b6971c9d440000a4a865',...
Craig Howell
1

votes
3

answer
72

Views

JQ Select Objects Where Inner Key Exists

I am trying to select credential objects only if key credhub-ref exist within them from the following JSON: { 'total_results': 23, 'total_pages': 1, 'prev_url': null, 'next_url': null, 'resources': [ { 'entity': { 'credentials': {}, 'binding_options': {}, 'gateway_data': null, 'gateway_name': '', 's...
Radford
1

votes
2

answer
52

Views

How to access an object inside a ViewController from within a TableViewCell

I am fairly new at coding in swift and I've been trying to find a solution to my problem for the past couple days, and am not able to. I have a class named userData with various properties: class UserData { var name: String var age: Int var credits: Int = 1 ... init(name: String, age: Int) { self.n...
1

votes
1

answer
22

Views

Unity3D , C# How to save position of objects and restart them later?

Dear StackOverFlow community, I need again your help in field of saving current position of objects in array. I need to save it because I want to restart level and their object to start position. I don't have idea how i can do it .. This is my code of objects and they moving as game proceed so I nee...
Simple aPPS
1

votes
2

answer
35

Views

What is the difference between just declaring array of object and actually creating instance of it?

Why does first statement output 'nothing1' and the second statement doesn't? If I am not wrong, then newly created array of object in statement second has default reference null. class Solution { public static void main (String[] args) throws java.lang.Exception { Animal temp1[]=null;//statement fir...
shreyash joshi
1

votes
2

answer
38

Views

Access an internal function within an array of functions

I have the following code, it is a variable that has an array of functions, but I can not access them, send an error. What I need between them is help but send me an error when trying to access one of them within the other. var mivarobject = function(){ this.helpers = { function1: function(){ return...
Lenin Zapata
1

votes
2

answer
45

Views

.fill() equivalent for Objects

I've tried googling this with terms such as 'fill equivalent for objects' but it insists on only showing me results for Arrays (which makes sense, since this is an array method). I know if it were an array, I could just do array.fill(0, 0, 28); However, I want to fill an object with a predetermined...
Lewis
1

votes
1

answer
58

Views

Why does my code not add every object into the vector?

I am reading from a file and with the information that I receive I want to parse the data and store them into their respectful objects which will then be pushed back into a vector. However, when the code stores the information into the object and is then pushed back into the vector, the vector does...
Darryl Brooks
1

votes
2

answer
41

Views

Accessing an instance variable within the `initialize` method

Given this basic class in Ruby: class TestClass def initialize(name) @name = name end end How do I then access the instance variable name directly from within the initialize method without creating a getter function? is this even possible? (i.e. using dot notation) or does the initialize method ceas...
seeker
1

votes
3

answer
93

Views

How to sort lists of objects using java

I have 2 lists which are holding the same objects but unordered and I want to sort them first before comparing them in order to check whether they are equals. One item of each list looks like that: first list: AuditRow{dateStr='2019-04-15 11:16', userStr='admin', entityStr='Users'} second list: Aud...
tupac shakur
1

votes
2

answer
38

Views

merge objects by key and create new key name

I have 2 object data. let continent = { 'BD': 'AS', 'BE': 'EU', 'BF': 'AF', 'BG': 'EU' } let capital = { 'BD': 'Dhaka', 'BE': 'Brussels', 'BF': 'Ouagadougou', 'BG': 'Sofia' } I want to merge it like this { 'BD': { 'continent': 'AS', 'capital': 'Dhaka', }, 'BE': { 'continent': 'EU', 'capital': 'Brus...
zynkn
1

votes
1

answer
26

Views

Getting the length of an array of objects in Reactjs

I have an array of objects: const boxOptions = [ { 0: '$250', 1: '$500', 2: '$750', 3: '$1000', 4: '$1250', 5: '$1500' }, { 0: '$500', 1: '$750', 2: '$1000', 3: '$1250', 4: '$1500', 5: '$2000' }, { 0: '$750', 1: '$1000', 2: '$1250', 3: '$1500', 4: '$2000', 5: '$2500' }, ] Which is set to the state a...
A7DC
1

votes
4

answer
50

Views

How do you print the names of variables inside of an array?

I have made an array and placed some variables in it, and I want to get the name of the variable using the index number. var a = 0; var b = 0; var c = 0; var letters = [a,b,c] console.log(letters) I want to have it output '[ a, b, c ]' but this code actually outputs '[0, 0, 0]' For more context, I p...
Jake F
1

votes
3

answer
18

Views

How to query a document with the highest value of a field

Let's say I have a collection of documents. To make this simpler, let's say all these documents have just 2 fields, name and id, like below. I want to get the document with the greatest value of 'id'. Can I use the .find({}) with some parameters? If so, I can't figure out which parameter would find...
lakers5824
1

votes
3

answer
41

Views

Sorting an object in an array through a method

This function sorts an array. First, the objects in which the country is equal to the one specified in the second argument should be displayed. Then all the rest. But I can not understand what is wrong? const arr = [ { 'name':'BMW', 'price':'55 000', 'country':'Germany', 'certificate':'yes'...
Gregori Roberts
1

votes
3

answer
22

Views

JavaScript object property not supported in IE?

I have the following code that works perfectly fine in Chrome etc, but doesn't work in IE 11: var fieldName='UserField'; var fieldValue='update value here...' var obj = { id: 123, [fieldName]: fieldValue }; var message='The field ['+ fieldName +'] will be updated with the value of ['+ obj[fieldName]...
DeclanMcD
1

votes
1

answer
57

Views

Remove a given entry from an object in javascript

Hello everyone with a function i want to remove an entry (which i give as an argument) from an object (which i also give as an argument). To make it clearer I will provide you some code. Here's the object I want to remove an entry from: const register = { aap :[{condition: {aap:'aap'}, func: 'fun'}...
Kevin
1

votes
2

answer
18

Views

How to delete dynamic property of an object?

I try to delete an dynamic property of an object. The problem is that the property is depending of an array of keys. Lets see the code : let keys = ['23', 'test', '12']; // Example but this is dynamic let temp = this.array; keys.forEach(k => { temp = temp[k]; }); delete temp; I want to delete this.a...
MatDepInfo
-1

votes
0

answer
34

Views

Is there a way to add an object to a list in a for loop

I have been trying to add a Rectangle object into a list. I am supposed to read in a file that the first line is for the canvas size and the rest of the lines are the dimensions of the rectangles. Ex. 300,300 75,75 25,25 50,50 100,100 61,61 I am able to read the lines into a list and split the li...
ChAnViNi
3

votes
3

answer
52

Views

Return different object types in case statement?

How can I return different object types in my case statement? public object?? CreateObjectType(JToken token) { switch (token['type'].Value()) { case 'Car': var Car = new Car(); return car; case 'Boat': var boat = new Boat(); return boat; ..... } } Do I need to create an abstract/interface class to...
Mask-dCodex
0

votes
0

answer
18

Views

How to check if an Integer variable of @RequestParam type in Spring is “empty”?

If I have a code in which: @RequestParam(value = 'amount', required = false) Integer amount is one of my parameters, what can I do to prevent the user from assigning an 'empty' value to this parameter? For example: let's suppose they requested, on Postman, the URL http://localhost:8080/myproject?amo...
LP0956
744

votes
21

answer
462.8k

Views

How can I access and process nested objects and arrays?

I have a nested data structure containing objects and arrays. How can I extract the information, i.e. access a specific or multiple values (or keys)? For example: var data = { code: 42, items: [{ id: 1, name: 'foo' }, { id: 2, name: 'bar' }] }; How could I access the name of the second item in items...
Felix Kling
1

votes
3

answer
32

Views

How can I pass a function to click handler in the correct context?

I have to get an argument value from the function inside the onlick property of a button, but the function (this.getListItemId(itemId)) which makes use of this argument is not inside of the context from where the button is. The button is inside a child function (this.renderVideoListTemplate()) whic...
Arthur Muller
0

votes
1

answer
28

Views

How to add a function as a method to a returned array?

I have a function intended to be used with the new constructor. It should return an array with a value of ['Hello World'] and include functions as methods. Here is a sample/demo (sorry if it's a little ugly): var my_object = function () { this.foo = function (data) { // alert and add new item alert(...
CW3
0

votes
0

answer
23

Views

Parse String (stdobject) in file to stdobject

I'm trying to parse a stdobject written in a file to a stdobject that I can use to code with. These are lines in a file. stdClass Object ( [result] => [NumberDocument] => 3 [Error] => 1 [Errors] => stdClass Object ) ob_start(); include_once('file.txt'); $result = ob_get_contents(); ob_end_...
1

votes
2

answer
2.8k

Views

Why is my ObjectInputStream throwing an EOFException?

I am writing a chat room code and each message is sent back and forth between client and server constantly. I have made all the messages into serialized objects and am using them to pass the information back and forth. Unfortunately this has led to an EOFException being thrown at the very first time...
KM529
1

votes
1

answer
542

Views

Getting Screen Size in Java as a Statric Variable [duplicate]

This question already has an answer here: Get effective screen size from Java 4 answers I am fairly new to Java so this probably has a simple solution but I just can't find the error. I want to get the screen size with a separate class (called Screen) and want it to be accessed as a static variable...
Ood
1

votes
7

answer
64

Views

Array.filter is returning empty array

I am trying to get the failure Details based on Date. For this I am applying array.filter but it is returning empty array. Below is my array: value:[{ 'Date': '02/04/2019', 'Total': '1000', 'Success': '850', 'Failure': '150', 'FailureDeatils': [{ 'Reason': 'Reason1', 'Count': 2 }, { 'Reason': 'Reaso...
kinnu
3

votes
3

answer
32

Views

How to convert Date format to `2019-04-24T04:27:14.867Z`

I need to send a Date to my backend in the following format: 2019-04-24T04:27:14.867Z I tried doing these: var d = new Date(); console.log(d); var utcDate1 = new Date(Date.UTC(96, 1, 2, 3, 4, 5)); console.log(utcDate1); var newFormat = new Date('04/21/19'); console.log(newFormat); Nothing works. wha...
user2024080
0

votes
2

answer
20

Views

How to assign values by property in nested object array using javascript

I would like to know how to assign values to object property in nested object by id=insta in javascript I have a two objects, I need apply one object property to another using javascript I got stuck and dont know how to proceed, obj1.forEach(e=> {if(e.id==='insta') Object.assign(e, obj2)}) var obj1...
Senthil
1

votes
1

answer
2.1k

Views

Sorting array of objects by property in MATLAB? [duplicate]

This question already has an answer here: Matlab - sort cell array of objects by property 1 answer I have an array of objects, each with various properties, and I would like to figure out how to run 'sort' on the array, specifying a specific property of each object to sort by. For example, say my...
user2716980
0

votes
3

answer
30

Views

What exactly is an object? [JavaScript]

Ive learned on MDN that an object is something with properties and method and that mostly everything in JavaScript is / can be treated as an object. Everything mentioned in the previous sentence makes it hard to tell what an object is. Some articles say that objects are just data containers others s...
iamlearningtocode
0

votes
0

answer
23

Views

Javascript Delete Collection

So i am trying to loop through a collection and delete all of the records. My code currently looks like this: if (ev.NewStatusName == 'Collect Initial Docs') { var count = ev.File.GetCollectionCount('Condition'); for (var a = 1; a
user982853
1

votes
1

answer
19

Views

Remove duplicates from nested map objects javascript

I'm displaying data on a grid using a nested map which looks like { this.state.rows.map((qc) => qc.BinsByDayByOrchardsQCs.map((qc2) => qc2.BinsByDayByOrchardsQCsDefects.map((qc3) => {console.log('results', qc3.Defect)} {qc3.Defect} ) ) ) } Which returns data that looks like this results Scuff resu...
invrt
-1

votes
0

answer
13

Views

How to access and manipulate values stored in an object's array?

I will use my project example to describe my problem. I have an object: Forest I have an array of 10 slots inside this object: 10 Trees In my code, I have assigned them random heights and growth rates: Call these height(1-10) and growth(1-10) I want to add a method where I can access these heights /...
Berk Mankaliye
3

votes
8

answer
77

Views

Create array of objects by key from array of objects

There are a lot of questions like this on here, but I couldn't find one that matched my needs. I'm looking for a relatively simple solution on how to stack objects in an array into new arrays based on a key. In the example data we're grouping the objects by their 'ship' key. Original data: var myObj...
Ian Gray
4

votes
3

answer
120

Views

Java bad practice doing: new… ().doSomething()?

I just saw a piece of code that had some classes with only one method. I picked an examples: public class TempDirCleanupProcess { public void cleanup(final File directory) {} } Then, later on in the code the method was called the following way: new TempDirCleanupProcess().cleanup(tempDir); Now I am...
ItFreak
1

votes
1

answer
2k

Views

Python: Delete Objects and Free Up Space

Python documentation said that an object is considered deleted if the reference counts to the object is zero and the difference between del and __del__ is that: del reduces the reference count to an object by one __del__ executes when the reference count to an object is zero That means if we keep de...
Daozui

View additional questions