K_PECT,
придумывайте переменным оригинальные имена ... да и в целом алгоритм стоит ещё раз продумать ...
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<script>
function send() {
var ARTKL01 = '1';
var ARTKL02 = '';
var ARTKL03 = '';
var ARTKL04 = '';
var ARTKL05 = '';
var kolichestvo01 = '1';
var kolichestvo02 = '';
var kolichestvo03 = '';
var kolichestvo04 = '';
var kolichestvo05 = '';
var textfield1 = '1';
var textfield2 = '';
var textfield3 = '';
var textfield4 = '';
var textfield5 = '';
var data = {
"pole1": textfield1,
"pole2": textfield2,
"pole3": textfield3,
"pole4": textfield4,
"pole5": textfield5,
"zakaz": [
{
"artikul":ARTKL01,
"kolichestvo":kolichestvo01,
},
{
"artikul":ARTKL02,
"kolichestvo":kolichestvo02,
},
{
"artikul":ARTKL03,
"kolichestvo":kolichestvo03,
},
{
"artikul":ARTKL04,
"kolichestvo":kolichestvo04,
},
{
"artikul":ARTKL05,
"kolichestvo":kolichestvo05
}
]
}
var output = '';
for (i in data.zakaz) {
if (data.zakaz[i].artikul != '') {
output+="<li>" + data.zakaz[i].artikul + "" + data.zakaz[i].kolichestvo + "</li>";
alert (output);
}
}
var obj = {};
Object.keys(data).forEach(function (key) {
if(key == 'zakaz'){
var arr = data[key].filter(function(el) {
return el.artikul && el.kolichestvo
});
if(arr.length) obj[key] = arr
}
else {
data[key] && (obj[key] = data[key])
}
});
alert(JSON.stringify(obj))
}
send()
</script>
</body>
</html>