Remove specific value inside string [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
What I'm doing I'm trying to remove the quotation in array in Java
this is the code
Array [ "johan|39012|manager|2010", "" ]
What I wanna or what I aspect
"johan|39012|manager|2010"

Try this and you will have an array with of good string:
const arr = [ "johan|39012|manager|2010", "" ];
const newArr = arr.filter(item => item.length > 0);
console.log(newArr);

Related

How to iterate and append characters of an array by push [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
var charArray=[a,b,c]
I want to have a new array as following:
var charArrayNew=[a, ab, abc]
Please suggest how to get the result of charArrayNew in ES6 Javascript.
You could do this:
const charArray=['a','b','c'];
const answer = charArray.map((_,i,ar)=>ar.slice(0,i+1).join(""));
console.log(answer);
// or, alternatively:
fn=(ar,res=[])=>(
ar.reduce((a,c)=>(res.push(a+=c),a),""),res );
console.log(fn(charArray))

REMOVE SPECIFIC NUMBER WITH JS [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'M TRYING TO HANDLE THIS DATA IN JAVASCRIPT SO HOW CAN I REMOVE DATA ACCORDING TO THE ID NUMBER THE FIRST NUMBER
600030/01/2018/163904
600010/01/2014/3789
600030/01/2020/47104
600030/01/2012/39104
600010/01/2011/93817
how can i remove all 600030 data so i get
600010/01/2014/3789
600010/01/2011/93817
If all data shaped in Array and element is instance of String.
I would recommend Array.prototype.filter and String.prototype.startsWith();
let data = [
'600030/01/2018/163904',
'600010/01/2014/3789',
'600030/01/2020/47104',
'600030/01/2012/39104',
'600010/01/2011/93817',
];
let filteredData = data.filter((d)=>!d.startsWith('600030'));
console.log( filteredData );
Result is
[
'600010/01/2014/3789',
'600010/01/2011/93817'
]

Split arrays into multiple arrays based on string characters [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
My Initial array:
var mainArray = ['car','incl','arc','linc','rca','icnl','meta','tame'];
I want the result like:
[['car','arc','rca'],['linc','icnl','incl'],['meta','tame']];
This is a compact version by using a closure for the sorted character array.
var array = ['car', 'incl', 'arc', 'linc', 'rca', 'icnl', 'meta', 'tame'],
result = Object.values(
array.reduce(
(r, s) => (a => ((r[a] = r[a] || []).push(s), r))([...s].sort()),
{}
)
);
console.log(result);

how to copy previous value in array (string) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
So how we can make a function that will take arrays of string like const numbers = ['1','2','0','3','0']
and change it for const changedNumbers = ['1','1','2','2','0','3','3','0']
Iterate with Array.map(). If '0' return '0', else return an array with two current string. Flatten by spreading into Array.concat():
const numbers = ['1','2','0','3','0']
const result = [].concat(...numbers.map((s) => +s ? [s, s] : s));
console.log(result);

Output array in javascript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
When I console.log(arrayname) I get this:
How do I Output the value "test"?
Just take the index of the array.
var arrayname = ['test'];
console.log(arrayname[0]);
// ^^^
var foo = Array('bar', 'baz', 'qux');
alert(foo[0]); //First item
alert(foo[1]); //Second item
alert(foo[2]); //Third item

Categories

Resources