truncate a string (javascript)

this sample will be used to truncate a string by number of words.

by Juan Muñoz

JavaScript

var some_string = "This is just a simple test of truncating after X words";
var truncate = function(str,num){
  var words = str.split(' ');
  words = words.splice(0,num);
  return words.join(' ');
}
console.log( truncate(some_string, 5) );