Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var arr= ["three", "2", "five", "ten", "111", 1, 2, "forty", "33", 33];
- var strArr = ["three", "2", "five", "ten", "111","forty", "33"];
- var numArr = [1, 2, 33];
- ['number', 'string'].map(i => arr.filter(a => typeof a == i));
- var arr= ["three", "2", "five", "ten", "111", 1, 2, "forty", "33", 33];
- var strArr = [];
- var numArr = [];
- var arrayLength = arr.length();
- // iterates trough the array
- for (i; i < arr.length(); i++)
- {
- //Check if the given value in the array is string
- if (typeof arr[i] === 'string')
- {
- // adds the value you are checking to the strArr
- strArr.push(arr[i]);
- }
- //Check if the given value in the array is integer
- if (typeof arr[i] === 'number' && isFinite(value))
- {
- // adds the value you are checking to the numArr
- numArr.push(arr[i]);
- }
- }
- var arr= ["three", "2", "five", "ten", "111", 1, 2, "forty", "33", 33];
- var num=[];
- var str=[];
- for(i=0;i<arr.length;i++){
- if(arr[i].includes(") || arr[i].includes('))
- str.push(arr[i]);
- else
- num.push(arr[i]);
- }
Add Comment
Please, Sign In to add comment