String.prototype extensions

A demonstration on how to extend Javascript objects using String.prototype as an example. We explore wc, words and take method extensions.

JavaScript

var question={
	questionId:1,
  questionName:'multiple choice #1',
  isAction:true,
  questionOptions:[
  	{optionId:1,optionName:'option1'},
    {optionId:2,optionName:'option2'}
  ],
  test:{
  	testId:5,
    testName:'test #'
  }
};

var newQuestion=removeChild(question);

console.log(newQuestion);
console.log(question);

function removeChild(o){
	var n=Object.assign({},o);
	Object.keys(n).forEach(function (key) {if(typeof n[key]==="object")delete n[key];});
  return n;
}