A plugin I use on my site generates an array in this style:
<script type="text/javascript">
window.slideDetails = [
//Slide1
"C1BP7: user information",
"FJAD7: user information",
"FFAD7: user information",
//Slide2
"C0AE7: user information",
"C7AZ7: user information",
"FJAE7: user information",
//Slide3
"C1AW7: user information",
"FJAP7: user information",
"FFAD7: user information"
];
</script>
I want to pass the first five characters to a cookie using the jQuery cookie plugin. Is it possible to truncate the array item to the first five characters?
I’m trying to get my head around the slice() but the different codes I’ve tried don’t work at all.
EDIT:
With thanks to andreas for his answer, I adapted it slightly to this:
window.slideCode = [], i;
for(var i = 0; i < window.slideDetails.length; i++) {
window.slideCode.push(window.slideDetails[i].substr(0, 5));
}
1 Answer