Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

like return result object action

I get the data: input
I need to find a match and assign it to a variable
How can I do that? ForEach dont work

console.log(input) // three
var ard = {
            one: `chekertest`,
            two: `chekertest`,
            three: `chekertest`,
            four: `chekertest`,
        }
        
        let text = []

        for (const input in ard) {
            // ???? like return result 
            
            text += input
          }

I did it right, but it doesn’t work for me for some reason.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You didn’t specify if you need an array of values, but I’m assuming you do.
Does this solve your problem?

const input = 'three'
console.log(input)
var ard = {
            one: `chekertest`,
            two: `chekertest`,
            three: `chekertest`,
            four: `chekertest`,
        }
const results = Object.entries(ard).filter(a => a[0] === input).map(r => r[1])

console.log(results) // ['chekertest']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading