How can I extract every 3rd character from a given string, such as the word GOOGLE? I have attempted to accomplish this using JavaScript, but I am unsure of what code to include after the 'if' statement.
function getNthElements(string) {
var stringLength = string.length;
var newString = [];
for(var i = 0; i < stringLength; i++) {
if(i % 3 == 0) {
// Insert code here to extract every 3rd character
}
newString.push(string[i]);
}
return newString;
}