the following code gets the page title, compares it with data in array and outputs me a final value
var title = (document.title);
//test variables
testarray =["blue","top","110","in stock", "red","down","111","in stock"]
//function
function testfunction(array, variable){
var varindex = array.indexOf(variable)
return array[varindex+2]
}
//calling the function
testfunction(testarray, title)
var finalvalue = testfunction(testarray, title);
So if my page title is Blue, it gives me the value 110 that is what I need. It works fine but in this way the only valid title for my page has to be Blue, otherwise it won't work.
I would like to be able to have a longer page title like Blue Shoes . I tried by adding the following variable at the beginning to get only the title first word
var fulltitle = (document.title);
var title = fulltitle.split(' ').slice(0,1);
but it doesn't work. What is wrong with my code ? thanks