isArray
function createLi(value) {
var html = '';
if (Array.isArray(value)) {
value.forEach(function (value) {
html += '<li>' + value + '</li>';
});
}
else if (typeof value === 'string') {
html = '<li>' + value + '</li>';
}
else {
console.log('不正な引数です');
}
return html;
}
var htmlA = createLi(['foo', 'bar', 'baz']);
var htmlB = createLi('foo');
console.log(htmlA);
// <li>foo</li><li>bar</li><li>baz</li>
console.log(htmlB);
// <li>foo</li>