M
M
mousesport2018-02-01 23:21:47
JavaScript
mousesport, 2018-02-01 23:21:47

How to properly get data from an object?

{"getuserworkersinfo":{"version":"1.0.0","data":{
"0":{"user":"ole.1","tag":"LD","rate":0,"auto":0},
"1":{"user":"ole.2","tag":"LD","rate":0,"auto":0},
"2":{"user":"ole.3","tag":"LD","rate":0,"auto":0},
"3":{"user":"ole.4","tag":"LD","rate":0,"auto":0},
"4":{"user":"ole.5","tag":"LD","rate":0,"auto":0},
"5":{"user":"ole.6","tag":"LD","rate":0,"auto":0},
"6":{"user":"ole.7","tag":"LD","rate":0,"auto":0}}}}

How to pull rate data for user ole.5?
for loop? Or not even alone?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Spirin, 2018-02-01
@mousesport

const { data } = response.getuserworkersinfo;

const targetUser = Object.values(data).find(({ user }) => user === 'ole.5');

const { rate } = targetUser;

Demo: https://jsfiddle.net/rockon404/s4gnjffz/

K
kn1ght_t, 2018-02-02
@kn1ght_t

https://jsfiddle.net/9ghe8htv/2/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question