JavaScript console.log and execution of function with Node.js and CoffeeScript

I compile CoffeeScript with node. In a script I have a function which clears arrays. I want to console.log the empty array. I can't see the difference between the 3 block logs:

clearArray = (arr) ->
  arr.splice 0 , arr.length

#Block 1
arr = [1,2]
clearArray arr
console.log arr

#Block 2
array = [1,2]
console.log clearArray array

#Block 3
console.log clearArray [1,2] 

#Block 1 logs: []
#Block 2 & 3 log: [ 1, 2 ]

In my understanding all Blocks should log "[ ]" and return an empty array, since clearArray returns the result of arr.splice(). It seems like #Block2 &3 do not execute the splice function?! Any help is much appreciated.

Answer:1

Splice() modifies the array in place and returns an array with the elements you remove.

var arr = [1, 2];
var a = arr.splice(0, 2);

console.log(arr);
[] 

console.log(a);
[1, 2]
Answer:2

In Backbone.js, there are two ways you can get the value of a single attribute: var foo = model.get('foo'); var foo = model.attributes.foo; The .get() approach is the one recommended in the docs, ...

In Backbone.js, there are two ways you can get the value of a single attribute: var foo = model.get('foo'); var foo = model.attributes.foo; The .get() approach is the one recommended in the docs, ...

  1. difference between backbone and spinal cord
  2. difference between backbone and vertebral column
  3. difference between backbone and underbone motorcycle
  4. difference between backbone js and angularjs
  5. difference between backbone and notochord
  6. difference between backbone and backhaul
  7. difference between backbone and gateway
  8. difference between backbone js and reactjs
  9. difference between backbone and angular
  10. difference between backbone and react
  11. difference between backbone and marionette
  12. difference between backbone cabling and horizontal cabling
  13. difference between backbone and exoskeleton
  14. difference between backbone js and knockout js
  15. difference between backbone and angularjs
  16. difference between backbone js and node js
  17. difference between backbone and spinal column
  18. difference between backbone and skeleton
  19. difference between backbone and side chains
  20. difference between backbone and spinal

I have an issue with my website. My page loads normally in Firefox, but when I use either Chrome or Safari, it goes to the bottom of the page and I don't understand why. I tried putting the following ...

I have an issue with my website. My page loads normally in Firefox, but when I use either Chrome or Safari, it goes to the bottom of the page and I don't understand why. I tried putting the following ...

  1. on loading page jquery
  2. on loading page javascript
  3. animation when loading page
  4. on page loading
  5. browser hangs when loading page
  6. progress bar when loading page
  7. chrome browser hangs when loading page
  8. jquery animation when page loading

I have a site where I'm using a JavaScript to add or remove a css class. Using this method I hide a div or show a div, as I need it. It works great. The problem is one div opens a Video with a ...

I have a site where I'm using a JavaScript to add or remove a css class. Using this method I hide a div or show a div, as I need it. It works great. The problem is one div opens a Video with a ...

I want to create a table with products on a certain menu of a store. The table is divided by categories (product categories) and for every category the desired products should be shown under his ...

I want to create a table with products on a certain menu of a store. The table is divided by categories (product categories) and for every category the desired products should be shown under his ...

  1. angularjs html table to excel
  2. angularjs html table example
  3. angularjs export html table to excel
  4. angularjs export html table to xlsx
  5. angularjs refresh html table
  6. angularjs export html table to pdf
  7. angularjs render html table
  8. angularjs dynamic html table
  9. angularjs filter html table
  10. angularjs json to html table
  11. angularjs ng-bind-html table
  12. angularjs ng-repeat html table
  13. angularjs-dynamic-table-html-form
  14. angularjs add/remove from html table using json
  15. angularjs get data from html table