array.forEach((item, index, array) => { if (array[index+1] && array[index+1].pId === item.pid) { console.log('前后的PID相等') } })