I have a wide range of data stored in the Data_Array below. How can I extract only the 5th and 6th indexes of the data automatically?
var Data_Array = ["BETA 135 MEMB 3 6",
"MATERIAL STEELAPPROX ALL",
"SUPPORTS",
"5 13 16 22 24 PINNED",
"20 FIXED",
"7 FIXED BUT FX KFY 200",
"9 FIXED BUT FZ MX KFY 150 KMZ 200",
"LOAD 1 LOADTYPE Dead TITLE DEAD",
"SELFWEIGHT Y -1",
"LOAD 2 LOADTYPE Live TITLE LIVE"]
I am aiming to extract the following values:
["7 FIXED BUT FX KFY 200",
"9 FIXED BUT FZ MX KFY 150 KMZ 200"]
I am attempting to write a code that iterates through all the arrays and stops when it encounters the word 'FIXED'. It then returns the length of that array as the first index. It continues to count until it reaches 'Load' as the second index. Here is an example code:
function countIndex(array, str1, str2){
count until Fixed then = gives 5
count until Load then = give 7
}
Array.splice(1st_index,2nd_index);
Although I have code that accomplishes this task, it only works when the specified strings are in the first index of an element. If the string "FIXED" is not in the first index, the code fails to detect it. Here is the existing code snippet:
function pullAllDataBetween(data, str1, str2) {
var string_nodes = [];
var append = false;
for (var i = 0; i < data.length; i++) {
if (data[i] === str1) {
append = true;
continue;
} else if (data[i] === str2) {
append = false;
break;
}
if (append) {
string_nodes.push(data[i]);
}
}
return string_nodes;
}