Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Get cheapest price phone from an object in javascript

const phones = [
    { name: 'samsung s5', price: 45000, camera: 10, storage: 32 },
    { name: 'walton', price: 15000, camera: 8, storage: 8 },
    { name: 'shaomi m3', price: 12000, camera: 10, storage: 16 },
    { name: 'oppo a2', price: 17000, camera: 10, storage: 32 },
    { name: 'Nokia n95', price: 8000, camera: 10, storage: 4 },
    { name: 'htc h81', price: 25000, camera: 10, storage: 16 }
]
let cheapest = phones[0];
for (let phone of phones) {
    if (phone.price < cheapest.price) {
        cheapest = phone;
    }
}
console.log(cheapest);
//{ name: 'Nokia n95', price: 8000, camera: 10, storage: 4 }
Comment

PREVIOUS NEXT
Code Example
Javascript :: Fibonacci perticular position in javascript 
Javascript :: convert nested json to query string 
Javascript :: scrollto element by id 
Javascript :: angular number pipe to four decimals 
Javascript :: mengakses gambar didalam asset angular 
Javascript :: flyweight 
Javascript :: if condition in jasper expression editor 
Javascript :: Search products by startsWith in javascript 
Javascript :: react date component with word month 
Javascript :: javascript get each element count / occurrences / frequency from a list 
Javascript :: char code to string javascript 
Javascript :: checkout code 
Javascript :: print multidimensional array javascript using loop 
Javascript :: Setting, getting, and removing data attributes vanilla javascript 
Javascript :: show tempdata in javascript 
Javascript :: falsy value in javascript 
Javascript :: cannot Nesting classes sass nextjs 
Javascript :: kube allow pod deployment on master node 
Javascript :: Implicit Return Shorthand in javascript 
Javascript :: react controllers 
Javascript :: string to number javascript shortcut 
Javascript :: on scroll image blur jquery 
Javascript :: cercle progress bar angular 
Javascript :: discord.js permission bitfield 
Javascript :: javascript get element by class domlist undefined 
Javascript :: 9.4.1.2. Loop Condition&para; 
Javascript :: basic routes 
Javascript :: typeorm class validation 
Javascript :: Electron manage windows 
Javascript :: react native update performance useReducer 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =