Skip to content

Instantly share code, notes, and snippets.

@oliveira-andre
Created November 2, 2019 19:54
Show Gist options
  • Select an option

  • Save oliveira-andre/7e5aa5c2a729dde3bf01f26e8936e47d to your computer and use it in GitHub Desktop.

Select an option

Save oliveira-andre/7e5aa5c2a729dde3bf01f26e8936e47d to your computer and use it in GitHub Desktop.
javascript as a pro
// show json as noob
let first_json = { programmer: 'Andre', hair_color: 'Black' }
let secound_json = { programmer: 'Noob guy', hair_color: 'yellow' }
console.log(first_json)
console.log(secound_json)
// show json as a pro:
console.log('%c my jsons', 'color: red; font-weight: bold;')
console.log({ first_json, secound_json })
// show json_array as a noob
let my_array = [first_json, secound_json]
console.log(my_array)
// show json_array as a pro
console.table(my_array)
// OR to verbose mode:
console.log(...my_array) // this is called spread
// get the json data as a noob
function noob_programmers(secound_json) {
return `name: ${secound_json.programmer}, hair_color: ${secound_json.hair_color}`
}
// get the json data as a pro
function pro_programmers({programmer, hair_color}) {
return `name: ${programmer}, hair_color: ${hair_color}`
}
// OR
function pro_programmers(first_json) {
let { programmer, hair_color } = first_json
return `name: ${programmer}, hair_color: ${hair_color}`
}
// concat json as a noob
let another_json = { foo: 'bar' }
let noob_concat = Object.assign(secound_json, another_json)
// concat json as a pro
let pro_concat = { ...first_json, ...another_json }
// OR
let another_pro_concat = { ...first_json, skill: 'javascript' }
// merge array as a noob
let some_array = ['foo', 'bar']
let noob_array = some_array.push(secound_json)
// merge array as a pro
let pro_array = [...some_array, first_json]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment