从JS变量打印值到div [英] Print values from JS variable to div
问题描述
var relationshipList => 如何将此变量的'title'和'firstname'值打印到div中? [
{name:'William Cotterll',名字:'William',标题:'EVP Solutions'},
{名称:'Edwin Van Der Saar',名字:'Edwin',标题:'安全专家'},
{姓名:'Kelly Woodson',名字:'Kelly',标题:'生产经理'},
];
编辑:
如果我想打印出'firstname'的值,当我已经知道'title'值时,我怎么能达到这个值?
例如,我只想打印出firstname标题=='EVP Solutions'。即使我因为某种原因提出问题而收到-1, p>
我想我知道了,
var Chkr;
Chkr = relationshipList;
if(relChkr [1] .title =='EVP Solutions'){
console.log(relChkr [1] .name);
} else {
console.log('');
};
不完美,但我现在可以将它放入div中,所以很好。
How would I print the 'title' and 'firstname' values from this variable into a div?
var relationshipList = [
{ name: 'William Cotterll', firstname: 'William', title: 'EVP Solutions' },
{ name: 'Edwin Van Der Saar', firstname: 'Edwin', title: 'Security Specialist' },
{ name: 'Kelly Woodson', firstname: 'Kelly', title: 'Production Manager'},
];
EDIT:
If I wanted to print out the 'firstname' value, when I already knew the 'title' value, how could I achieve that?
For example, I only want to print out firstname when the title == 'EVP Solutions'.
Even though I received -1 for some reason for asking a question,
I think I figured it out,
var Chkr;
Chkr = relationshipList;
if(relChkr[1].title == 'EVP Solutions'){
console.log(relChkr[1].name);
}else{
console.log('');
};
Not perfect but I can throw it into a div now so is all good.
这篇关于从JS变量打印值到div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!