kaniosrn-j
3/30/2017 - 4:03 PM

Loop an object - es6

Loop an object - es6

var friends = [{
  name: 'John',
  age: 30
}, {
  name: 'Ana',
  age: 20
}, {
  name: 'Chris',
  age: 25
}];

function comparePerson(a, b) {
  if (a.age < b.age) {
    return -1
  }
  if (a.age > b.age) {
    return 1
  }
  return 0;
}
console.log(friends.sort(comparePerson));

	const apple = {
		color: 'red',
		size: 'Medium',
		weight: 50,
		sugar: 10
	};


	for(const prop of Object.keys(apple)){
		const value = apple[prop]
		console.log(value)

	}