Given an array and a string, how can we push whole words that contain the word 'WORD' into the array?
var arr = [];
var str='This is mWORDy word docuWORDment';
if (str.indexOf('WORD') > -1) {
arr.push(Whole word here)
}
Although the current code works, we aim to modify it so that we achieve this result:
arr['mWORDy','docuWORDment'];
How can we accomplish this task efficiently?