ds-algo-study
Version:
Just experimenting with publishing a package
30 lines (22 loc) • 822 B
JavaScript
/***********************************************************************
Write a function called `keysInObject(obj)` that takes in an object and returns
an array of all the keys within that Object.
Do this once using using a `for...in` loop and once using `Object.keys`.
Examples:
let animals = {dog: 'Wolfie', cat: 'Jet', bison: 'Bilbo'}
let foods = {apple: 'tart', lemon: 'sour', mango: 'sweet'}
keysInObject(animals); // => ["dog", "cat", "bison"]
keysInObject(foods); // => ["apple", "lemon", "mango"]
***********************************************************************/
function keysInObject(obj) {
return Object.keys(obj);
}
// solution 2
// function keysInObject(obj) {
// let array = [];
// for (key in obj) {
// array.push(key);
// }
// return array;
// }
module.exports = keysInObject;