Output array in javascript [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 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

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))

How to pass index value and get name from array response angular [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
onRowClick function, i am getting index id.
Try this below :
onRowClick($event) {
const indexid= $event;
this.tagPolicesArray['records'].map(function(item, index){
if(index == indexid){
console.log(item['name']); ----------------> Here you will get your required name
}
});
}

Remove specific value inside 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 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);

How can I assign variable from json? [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 5 years ago.
Improve this question
So my codes are like below;
$.getJSON('https://api.myjson.com/bins/gxs81',function(data){
$.each(data.employees,function(i,emp){
$('ul').append('<li>'+emp.firstName+' '+emp.lastName+'</li>');
});
I have multiple objects in json file, how can I assign them in an array? e.g.
array[2][0]=*firstName field should be here*
array[2][1]=*lastname field should be here*
Here's a simple push() to build a new array from your JSON:
$.getJSON('https://api.myjson.com/bins/gxs81',function(data){
var current = '';
var myarray = [];
$.each(data.employees,function(i,emp){
current = emp.firstName+' '+emp.lastName;
$('ul').append('<li>'+current+'</li>');
myarray.push(current);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul></ul>

How can i get array key-values pair using 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 7 years ago.
Improve this question
for(i=0;i<=array_values.length;i++){
var a=array_values[i].amounts;
var t=array_values[i].Tax;
alert(a);
alert(t);
}
Error : TypeError: array_values[i] is undefined
var a=array_values[i].amounts;
var a=array_values[i].amounts;
change
for(i=0;i<=array_values.length;i++)
to
for(i=0;i<array_values.length;i++)
<= to <

Categories

Resources