JSFiddle - React, Tailwind, and code Playground

by Steven Senkus

JavaScript

class TestClass {

    constructor() {
        
    }
    
    initialize() {
        this.items = [{
            type: 'a',
            value: 10,
        }, {
            type: 'b',
            value: 20,
        }, {
            type: 'c',
            value: 50,
        }, {
            type: 'd',
            value: 100,
        }];
    }

    getValueByType(type) {
        const itemByType = this.items.find(value => value.type === type);
        
        return itemByType.value;
    }

}


const test = new TestClass();
test.initialize();
console.log(test.getValueByType('w'))